﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using ESOL.Business.Mst;
using ESOL.Business.Fin;
using ESOL.Common;
using ESOL.Common.Entity;
using ESOL.WinUI.MasterData;
using ESOL.WinUI.Hr;

namespace ESOL.WinUI.Finance
{
    public partial class frmMaintainPrepaidAmountHistory : BaseForm.frmBaseDialogyQueryForm
    {
        private MstPersonEntity mSelectedPerson;

        public frmMaintainPrepaidAmountHistory(MstPersonEntity person)
        {
            InitializeComponent();
            mSelectedPerson = person;
        }
        private string GetCondition()
        {
            string condition = " AND AA.STATUS = 'AMS04'";
            if (mSelectedPerson != null)
            {
                condition += " AND AA.PERSON_ID = '" + mSelectedPerson.PersonId + "'";
            }
            return condition;
        }
        private void BindDataGrid()
        {
            string condition = GetCondition();
            string orderBy = "ADVANCE_DATE DESC";
            DataTable dt = FinAdvanceAmountBs.GetByCondition(condition, orderBy, "");
            gvMain.DataSource = dt;
        }

        protected override void OnShown(EventArgs e)
        {
            base.OnShown(e);
            if (mSelectedPerson != null)
            {
                txtPerson.Text = mSelectedPerson.NameCn;
                txtLeftAdvanceAmount.Text = mSelectedPerson.AdvanceAmount.ToString("#0.00");
            }
            UICommon.UICommonFunctions.BindGridComboboxByCommonItem(colADVANCE_TYPE, "ADT", true);
            BindDataGrid();
        }

        private void gridView1_RowClick(object sender, DevExpress.XtraGrid.Views.Grid.RowClickEventArgs e)
        {

        }

        private void txtPerson_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            frmMaintainEmployeeQuery frm = new frmMaintainEmployeeQuery(true);
            if (frm.ShowDialog() == DialogResult.OK && frm.SelectedPerson != null)
            {
                mSelectedPerson = frm.SelectedPerson;
                txtPerson.Text = frm.SelectedPerson.NameCn;
                txtLeftAdvanceAmount.Text = frm.SelectedPerson.AdvanceAmount.ToString("#0.00");
                BindDataGrid();
            }
            else
            {
                mSelectedPerson = null;
                txtPerson.Text = "";
                txtLeftAdvanceAmount.Text = "";
                gvMain.DataSource = null;
            }
        }


    }
}
